//
//  pushTransitionAnimation.m
//  练习转场动画
//
//  Created by 苗钧豪 on 16/8/23.
//  Copyright © 2016年 苗钧豪. All rights reserved.
//

#import "pushTransitionAnimation.h"
#import "TableViewController.h"
#import "ViewController.h"
@implementation pushTransitionAnimation




- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {
    return 0.5;
}
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
    TableViewController *tvc = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    ViewController *vc = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIView *containerView = [transitionContext containerView];
    [containerView addSubview:vc.view];
    vc.twoimgview.hidden = YES;
    vc.twoimgview.image = [UIImage imageNamed:_imgstring];
    vc.twotextview.text = _txtstring;
    // 截图
    UIView *snapView = [_cell.oneimgview snapshotViewAfterScreenUpdates:NO];
    CGRect rect = [_cell.oneimgview convertRect:_cell.frame toView:vc.view];
    if (rect.origin.y != 64) {
        rect.origin.y = rect.origin.y / 2;
    }
    snapView.frame = rect;
    [containerView addSubview:snapView];
    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
        [containerView layoutIfNeeded];
        snapView.frame = CGRectMake(0, 0, 375, 228);
    } completion:^(BOOL finished) {
        vc.twoimgview.hidden = NO;
        [snapView removeFromSuperview];
        [transitionContext completeTransition:YES];
    }];

}
@end
